package cx3k.main;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.xerces.*;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import cx3k.dataAccess.*;
import cx3k.scheduler.objects.AcademicYear;
import cx3k.scheduler.objects.Course;
import cx3k.scheduler.objects.Schedule;
import cx3k.scheduler.objects.ScheduledSemester;
import cx3k.scheduler.objects.Semester;


public class XMLFile {

	/**
	 * @author charles
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		List<Schedule> theSchedules;
		
		System.out.println("Welcome to the cx3k scheduler!\n");
		
		ScheduleManager test = new ScheduleManager(new File("load_schedule.xml"));
		//test.save(new Schedule());
		theSchedules = test.loadAll();
		
		ScheduleManager writeToXML = new ScheduleManager(new File("written_xmlfile.xml"));
		writeToXML.save(test.load(100));
		System.out.println("\n\ndone!");
		/*
		for(int i = 0; i < theSchedules.size(); i++){
			System.out.println(theSchedules.get(i).toString());
			Set<AcademicYear> tempAY = theSchedules.get(i).getAcademicYear();
			Iterator<AcademicYear>AYITER = tempAY.iterator();

			while(AYITER.hasNext()){
				System.out.print("\n********** New Academic Year ***********\n");
				AcademicYear currentY = AYITER.next();
				System.out.println(currentY.toString());
				Collection<ScheduledSemester> theSemesters = currentY.getSemesters();
				Iterator<ScheduledSemester> SSITER = theSemesters.iterator();
				
				while(SSITER.hasNext()){
					ScheduledSemester currentSemester = SSITER.next();
					System.out.println(currentSemester.toString());
					
					Set<Course> currentCourses = currentSemester.getCourses();
					Iterator<Course> CEITER = currentCourses.iterator();
					
					while(CEITER.hasNext()){
						Course currentCourse = CEITER.next();
						System.out.print("\tCourseId: " + currentCourse.getCourseId());
						System.out.print("\tDegreeProgram: " + currentCourse.getDegreeProgram());
						System.out.println("\tCourseNumber: " + currentCourse.getCourseNum());
					}
					
				}
			}
			
		}
		*/
		//test.save(new Schedule(10,15,"Scoll10"));
		//test.delete(123);
		//test.delete(100);
		//test.delete(128);
		
		//ScheduleManager test2 = new ScheduleManager(new File("writen_schedule.xml"));
		
		//List<Course> courses = new ArrayList();
		//courses.add(new Course(1, new Semester(1010, 1999, "SPRING"), "course1"));
		//courses.add(new Course(1, new Semester(1011, 1999, "SPRING"), "course1"));
		//courses.add(new Course(1, new Semester(2131, 1999, "SPRING"), "course1"));
		//courses.add(new Course(1, new Semester(1005, 1999, "SPRING"), "course1"));
		//courses.add(new Course(1, new Semester(2, 1999, "FALL"), "course2"));
		//courses.add(new Course(1, new Semester(3, 1999, "SPRING"), "course3"));
		
		//Schedule theSchedule = new Schedule(5,15, "Schedule1", courses);
		//test2.save(theSchedule);
	
	}

}
